package org.example.SolutionNew001;

import java.util.HashSet;
import java.util.Set;

public class Window01 {
    public static void main(String[] args) {
        Window01 win = new Window01();
        String s="pwwkew";
        System.out.println(win.lengthOfLongestSubstring(s));
    }

    public int lengthOfLongestSubstring(String s) {
        int n = s.length();
        Set<Character> set = new HashSet<Character>();
        int right=-1,ans=0;
        for(int i=0;i<n;i++){
            if(i!=0){
                set.remove(s.charAt(i));
            }
            while(right+1<n&&!set.contains(s.charAt(right+1))){
                set.add(s.charAt(right+1));
                right++;
            }
            ans=Math.max(ans,right-i+1);
        }
        return ans;
    }
}
